package at.tuwien.seminar.scrum1.view.room.update;

import at.tuwien.seminar.scrum1.model.Bill;
import at.tuwien.seminar.scrum1.model.Customer;
import at.tuwien.seminar.scrum1.proxies.ReservationProxy;
import at.tuwien.seminar.scrum1.view.bill.list.BillList;
import at.tuwien.seminar.scrum1.view.customer.list.CustomerList;
import at.tuwien.seminar.scrum1.view.reservation.list.ReservationList;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.validation.validator.MinimumValidator;
import org.apache.wicket.validation.validator.RangeValidator;
import org.apache.wicket.validation.validator.StringValidator;

import at.tuwien.seminar.scrum1.model.Room;
import at.tuwien.seminar.scrum1.proxies.RoomProxy;
import at.tuwien.seminar.scrum1.view.room.list.RoomList;

public class UpdateRoom extends WebPage {
	
	public UpdateRoom(Room room)
	{

        add(new Link<Room>("roomLink") {

			@Override
			public void onClick() {
				setResponsePage(new RoomList());
			}

		});
		add(new Link<Customer>("customerLink") {

			@Override
			public void onClick() {
				setResponsePage(new CustomerList());
			}

		});

        add(new Link<Customer>("reservationLink") {

			@Override
			public void onClick() {
				setResponsePage(new ReservationList(ReservationProxy.getInstance().getAll()));
			}

		});

         add(new Link<Bill>("billLink") {

			@Override
			public void onClick() {
				setResponsePage(new BillList());
			}

		});

		Form<Room> form = new Form<Room>("roomForm", new CompoundPropertyModel<Room>(room))
		{
			@Override
			protected void onSubmit()
			{
				RoomProxy.getInstance().updateRoom(getModelObject());
				setResponsePage(new RoomList());
			}
		};
		
		form.add(new TextField<String>("name").
				setRequired(true).
				add(StringValidator.maximumLength(40)));
		form.add(new TextField<Integer>("maxNumberOfPersons").
				setRequired(true).
				add(new RangeValidator<Integer>(1,10)));
		form.add(new TextField<Double>("priceSingleRoom").
				setRequired(true).
				add(new MinimumValidator<Double>(0.0)));
		form.add(new TextField<Double>("priceDoubleRoom").
				add(new MinimumValidator<Double>(0.0)).
				setRequired(false));
		form.add(new TextField<Double>("priceTripleRoom").
				add(new MinimumValidator<Double>(0.0)).
				setRequired(false));
		form.add(new TextField<Double>("priceSingleRoomWithChild").
				setRequired(false).
				add(new MinimumValidator<Double>(0.0)));
		form.add(new TextField<Double>("priceSingleRoomWithTwoChild").
				setRequired(false).
				add(new MinimumValidator<Double>(0.0)));
		form.add(new TextField<Double>("priceDoubleRoomWithChild").
				setRequired(false).
				add(new MinimumValidator<Double>(0.0)));
		form.add(new Button("submit"));
		form.add(new FeedbackPanel("feedback"));
		
		add(form);
		
		add(new Link<Room>("back") {
			@Override
			public void onClick() {
				setResponsePage(new RoomList());

			}
		});
	}
}
